﻿CREATE TABLE [dbo].[FactTrackSales](
	[FactTrackSaleId] [int] identity(1,1),
	[InvoiceLineId] [int] NOT NULL DEFAULT -1,
	[InvoiceId] [int] NOT NULL DEFAULT -1,
	[InvoiceDateId] [int] NOT NULL DEFAULT -1,
	[TrackId] [int] NOT NULL DEFAULT -1,
	[GenreId] [int] NOT NULL DEFAULT -1,
	[MediaTypeId] [int] NOT NULL DEFAULT -1,
	[CustomerId] [int] NOT NULL DEFAULT -1,
	[UnitPrice] [numeric](10, 2) NOT NULL,
	[Quantity] [int] NOT NULL,
	[Amount]  AS ([UnitPrice]*[Quantity]),
 [TaskExecutionLogId] INT NOT NULL DEFAULT 0, 
    CONSTRAINT [PK_FactTrackSale] PRIMARY KEY CLUSTERED 
(
	[FactTrackSaleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO




ALTER TABLE [dbo].[FactTrackSales]  WITH CHECK ADD  CONSTRAINT [FK_FactTrackSales_DimCustomer] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[DimCustomer] ([CustomerId])
GO

ALTER TABLE [dbo].[FactTrackSales] CHECK CONSTRAINT [FK_FactTrackSales_DimCustomer]
GO

ALTER TABLE [dbo].[FactTrackSales]  WITH CHECK ADD  CONSTRAINT [FK_FactTrackSales_DimGenre] FOREIGN KEY([GenreId])
REFERENCES [dbo].[DimGenre] ([GenreId])
GO

ALTER TABLE [dbo].[FactTrackSales] CHECK CONSTRAINT [FK_FactTrackSales_DimGenre]
GO

ALTER TABLE [dbo].[FactTrackSales]  WITH CHECK ADD  CONSTRAINT [FK_FactTrackSales_DimMediaType] FOREIGN KEY([MediaTypeId])
REFERENCES [dbo].[DimMediaType] ([MediaTypeId])
GO

ALTER TABLE [dbo].[FactTrackSales] CHECK CONSTRAINT [FK_FactTrackSales_DimMediaType]
GO

ALTER TABLE [dbo].[FactTrackSales]  WITH CHECK ADD  CONSTRAINT [FK_FactTrackSales_DimTrack] FOREIGN KEY([TrackId])
REFERENCES [dbo].[DimTrack] ([TrackId])
GO

ALTER TABLE [dbo].[FactTrackSales] CHECK CONSTRAINT [FK_FactTrackSales_DimTrack]
GO



